<?php
namespace CAI\HistoricoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use CAI\HistoricoBundle\Entity\Partido;
use CAI\HistoricoBundle\Entity\Equipo;
use CAI\HistoricoBundle\Form\Type\PartidoType;
use CAI\HistoricoBundle\Form\Type\EquipoType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use \DateTime;

class IndexController extends Controller
{
	public function headerAction(Request $request)
	{
		$partido = new Partido();
		$form = $this->createForm(new PartidoType(), $partido);
		return $this->render('CAIHistoricoBundle:Default:bootstrap.header.html.php', array('form' => $form->createView()));
	}

	public function indexAction(Request $request)
	{
		$repository = $this->getDoctrine()->getRepository('CAIHistoricoBundle:Partido');
		$partidos = $repository->findBy(array(), array('partidos_dia' => 'DESC'), 8);

		$emConfig = $this->getDoctrine()->getManager()->getConfiguration();
		$emConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Mysql\Month');
		$emConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\Query\Mysql\Day');

		$qb = $repository->createQueryBuilder('p');
		$qb->select('p')
			->Where('MONTH(p.partidos_dia) = :month')
			->andWhere('DAY(p.partidos_dia) = :day');

		$qb->setParameter('month', date("m"))
			->setParameter('day', date("d"));

		$partidosHoy = $qb->getQuery()->getResult();

		return $this->render('CAIHistoricoBundle:Default:bootstrap.partidos.html.php', array('partidosHoy' => $partidosHoy, 'partidos' => $partidos));

	}
	
	public function equiposAction(Request $request)
	{
		
		$equipo = new Equipo();
		$formEquipo = $this->createForm(new EquipoType(), $equipo);
		return $this->render('CAIHistoricoBundle:Default:equipos.html.php', array('form' => $formEquipo->createView()));
	}
	
	public function thanksAction()
	{
		return $this->render('CAIHistoricoBundle:Default:thanks.html.php');
	}
}